package com.xxl.sso.server.util;

import org.bouncycastle.crypto.digests.SM3Digest;
import org.bouncycastle.util.encoders.Hex;

public class Sm3Util {
    
    /**
     * Calculate SM3 hash for the input string
     * 
     * @param input the input string
     * @return the hex representation of the SM3 hash
     */
    public static String sm3(String input) {
        if (input == null) {
            return null;
        }
        
        SM3Digest digest = new SM3Digest();
        byte[] inputBytes = input.getBytes();
        digest.update(inputBytes, 0, inputBytes.length);
        
        byte[] hashBytes = new byte[digest.getDigestSize()];
        digest.doFinal(hashBytes, 0);
        
        return new String(Hex.encode(hashBytes));
    }
}